﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Xml;

namespace simpleDns
{
    public partial class loadProcess : Form
    {
        public loadProcess()
        {
            InitializeComponent();
        }
        private void loadDomain(string dataPath)
        {
            DirectoryInfo di = new DirectoryInfo(dataPath);
            FileInfo[] fis = di.GetFiles("*.dns", SearchOption.TopDirectoryOnly);
            progressBar1.Maximum = fis.Length;
            progressBar1.Value = 0;
            foreach (FileInfo fi in fis)
            {
                DOMAIN dm = new DOMAIN();
                try
                {
                    dm.loadFromFile(fi.FullName);
                    if (!settings.domains.ContainsKey(dm.name))
                    {
                        settings.domains.Add(dm.name, dm);
                    }
                }
                catch
                {
                    //TODO:
                }

                progressBar1.Value++;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void loadProcess_Load(object sender, EventArgs e)
        {
            loadDomain(settings.dataPath);
        }
    }
}
